package com.fita.admin.entity.search.report;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.fita.entity.order.OrderPayType;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: 11200
 * @date: 2019/7/26
 */
public class RechargeRecordSearch implements QueryBuilder {

    private Date beginPayTime;

    private Date endPayTime;

    private OrderPayType orderPayType;

    private List<Long> agents;

    //-----------------------------

    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * get prepared filter
     *
     * @param refresh whether to re-create filter
     * @return
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (refresh || queryFilter == null){

            queryFilter = new QueryFilter();


        }

        return queryFilter;
    }

    /**
     * build query string template (sql or hql with :keys)
     *
     * @return
     */
    public String buildSentenceTemplate() {
        return "FROM RechargeRecord WHERE disabled = false AND status != 'UNPAID' " + getPreparedFilter(false).clauseSentence() + getOrder().sentence();
    }

    /**
     * get order
     *
     * @return
     */
    public QueryOrder getOrder() {

        if (queryOrder == null){
            queryOrder = new QueryOrder("id", "DESC");
        }
        return queryOrder;
    }

    /**
     * build query string template corresponding parameters
     *
     * @return
     */
    public Map<String, Object> buildParameters() {
        return queryFilter.parameters();
    }


}
